package com.hex.liyue.lookingdatemodule.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hex.liyue.LiYueApplication;
import com.hex.liyue.R;
import com.hex.liyue.lookingdatemodule.bean.AppointmentDetailsResultBean;
import com.hex.liyue.storemodule.bean.FragmentStoreBean;

import java.util.List;

/**
 * Created by WJ on 2016/6/12.
 */
public class AdapterCommissioned extends RecyclerView.Adapter<AdapterCommissioned.MyHolder> {
    private OnItemClickListener onItemClickListener;
    private   AppointmentDetailsResultBean.DataBean.ApplyListBean.GiftListBean giftListBean;

    private List<AppointmentDetailsResultBean.DataBean.ApplyListBean.GiftListBean> list;

    public void setList(List<AppointmentDetailsResultBean.DataBean.ApplyListBean.GiftListBean> list) {
        this.list = list;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClickListener(int position);
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.commissioned_item, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, final int position) {
        giftListBean = list.get(position);
//        holder.rl_store.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                onItemClickListener.onItemClickListener(position);
//            }
//        });
        holder.tv_dis_desc.setText(giftListBean.gift_brand);
        holder.tv_dis_name.setText(giftListBean.gift_name);
        holder.tv_dis_price.setText("单价：￥" + giftListBean.price);
        holder.tv_dis_num.setText("数量：X" + giftListBean.status);
        Glide.with(LiYueApplication.getInstance())
                .load(giftListBean.gift_url)
                .error(R.drawable.no_icon)
                .into(holder.iv_icon);
    }

    @Override
    public int getItemCount() {
        if (list.size()== 0) {
            return 0;
        }
        return list.size();
    }


    class MyHolder extends RecyclerView.ViewHolder {
        RelativeLayout rl_store;
        TextView tv_dis_desc, tv_dis_name, tv_dis_num,tv_dis_price;
        ImageView iv_icon;

        public MyHolder(View itemView) {
            super(itemView);
//            rl_store = (RelativeLayout) itemView.findViewById(R.id.rl_store);
            iv_icon = (ImageView) itemView.findViewById(R.id.iv_icon);
            tv_dis_desc = (TextView) itemView.findViewById(R.id.tv_dis_desc);
            tv_dis_name = (TextView) itemView.findViewById(R.id.tv_dis_name);
            tv_dis_num = (TextView) itemView.findViewById(R.id.tv_dis_num);
            tv_dis_price = (TextView) itemView.findViewById(R.id.tv_dis_price);
        }

    }
}
